<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="" method="post">
	<input type="hidden" id="id" name="id" value="${db.id }">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.resourcemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.update.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.ip") %></label>
						<span><input type="text" id="ip" name="ip" value="${db.ip}" maxlength="16" size="22" class="validate[required,custom[ipv4]]"/></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.port") %></label>
						<span><input type="text" id="port" name="port" value="${db.port}" maxlength="16" size="22" class="validate[required,custom[integer]]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.dbname") %></label>
						<span><input disabled="disabled"  value="${db.dbname}" class="validate[required]"/></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.username") %></label>
						<span><input type="text" id="username" name="username" value="${db.username}" maxlength="16" size="22" class="validate[required]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.password") %></label>
						<span><input type="password" id="password" name="password" value="${db.password}" maxlength="16" size="22" class="validate[required]" /></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.totalconn") %></label>
						<span><input type="text" id="totalconn" name="totalconn" value="${db.totalconn}" maxlength="16" size="22" class="validate[required,custom[integer]]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.usedconn") %></label>
						<span><input disabled="disabled"  value="${db.usedconn}" class="validate[required]"/></span>
					</li>
				</ul>	
       		</div>
       		<div class="button-group">
       			<input type="hidden" name="id" id="id" value="${agreement.id}"/>
       			<input type="hidden" id="isCommon" name="isCommon" value='' />
       	 		<input type="button" class="btn btn-default" id="butCommon" name="butCommon" value='<%=MessageResourcesUtils.getMessage(request, "common.button.common") %>' />
       			<input type="button" class="btn btn-default" id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       			<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	
	$('#butSave').click(function() {
		var exp = $('#form1').validationEngine('validate');
		
		if(exp==true)
		{
			var isCommon = $('#isCommon').val();
			if(isCommon == ''){
				alert('<%=MessageResourcesUtils.getMessage(request, "alertinfo.databaseresource.java.alert3")%>')
			}else if(isCommon == '0'){
				alert('<%=MessageResourcesUtils.getMessage(request, "alertinfo.databaseresource.java.alert4")%>')
			}else if(isCommon == '1'){
				form1.action="${systemctx}/systemmanage/databaseresource/updateDatabaseResource.web";
				form1.submit();
			}
		}
	});
	
	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
	
	$('#butCommon').click(function() {
		var exp = $('#form1').validationEngine('validate');
		if(exp==true)
		{
			showSending();
			$.ajax({
    			type : 'POST',
				url : '${systemctx}/systemmanage/databaseresource/testCommon.json',
				dataType : 'json',
				data: $("#form1").serialize(),
				success : function(data) {
					closeSending();
					if (data.messagetype == '2')
			    	{
						//提示连接失败，则设置为0.
						$.fn.ajaxmessage(data);
						$('#isCommon').val('0');
			    	}else{
			    		//提示连接成功，则设置为1.
			    		$.fn.ajaxmessage(data);
						$('#isCommon').val('1');
			    	}
				}
    		});
		}
	});
});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>